import java.util.Arrays;

public class RotatingArray {
    public static void main(String[] args) {
        int k = 3;//向右旋转位数
        int[] num = {5, 6, 7, 1, 2, 3, 4};

        rotate(num, k);
        System.out.println("旋转后数组为：");
        System.out.println(Arrays.toString(num));
    }

    public static void rotate(int[] num, int k) {
        int[] re_num = new int[num.length];//相较num.clone运行更快
        k = k % num.length;
        int i;

        for (i = 0; i < num.length; i++) {
            re_num[(i + k) % num.length] = num[i];
        }

        for (i = 0; i < num.length; i++) {
            num[i] = re_num[i];
        }
    }
}
